<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.0.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '7.5.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: '',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    },
    sidebarPadding: 40
  };
</script>

  <meta name="description" content="简单交流界面设计：简单的对之前的一些知识进行综合运用！">
<meta name="keywords" content="计算机,语言,python,交互式图形编程">
<meta property="og:type" content="article">
<meta property="og:title" content="程序扩充">
<meta property="og:url" content="https:&#x2F;&#x2F;chasemyking.github.io&#x2F;2019&#x2F;12&#x2F;21&#x2F;%E7%A8%8B%E5%BA%8F%E6%89%A9%E5%85%85&#x2F;index.html">
<meta property="og:site_name" content="chasemyking">
<meta property="og:description" content="简单交流界面设计：简单的对之前的一些知识进行综合运用！">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https:&#x2F;&#x2F;chasemyking.github.io&#x2F;images&#x2F;与python聊天.png">
<meta property="og:image" content="https:&#x2F;&#x2F;chasemyking.github.io&#x2F;images&#x2F;时钟.png">
<meta property="og:image" content="https:&#x2F;&#x2F;chasemyking.github.io&#x2F;images&#x2F;snowfall.png">
<meta property="og:image" content="https:&#x2F;&#x2F;chasemyking.github.io&#x2F;images&#x2F;Rainbow.png">
<meta property="og:updated_time" content="2019-12-22T03:33:14.353Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https:&#x2F;&#x2F;chasemyking.github.io&#x2F;images&#x2F;与python聊天.png">

<link rel="canonical" href="https://chasemyking.github.io/2019/12/21/%E7%A8%8B%E5%BA%8F%E6%89%A9%E5%85%85/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>程序扩充 | chasemyking</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?0e2a4e5bd5a98fcd51a1d8d5405bdfb8";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">chasemyking</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://chasemyking.github.io/2019/12/21/%E7%A8%8B%E5%BA%8F%E6%89%A9%E5%85%85/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/chasemyking.jpg">
      <meta itemprop="name" content="chasemyking">
      <meta itemprop="description" content="我永远喜欢艾斯德斯！">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="chasemyking">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          程序扩充
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-12-21 17:00:49" itemprop="dateCreated datePublished" datetime="2019-12-21T17:00:49+08:00">2019-12-21</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-12-22 11:33:14" itemprop="dateModified" datetime="2019-12-22T11:33:14+08:00">2019-12-22</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%AD%A6%E4%B9%A0/" itemprop="url" rel="index">
                    <span itemprop="name">学习</span>
                  </a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%AD%A6%E4%B9%A0/%E7%AC%94%E8%AE%B0/" itemprop="url" rel="index">
                    <span itemprop="name">笔记</span>
                  </a>
                </span>
            </span>

          
            <span id="/2019/12/21/%E7%A8%8B%E5%BA%8F%E6%89%A9%E5%85%85/" class="post-meta-item leancloud_visitors" data-flag-title="程序扩充" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>4.8k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>4 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>简单交流界面设计：<br>简单的对之前的一些知识进行综合运用！</p>
<a id="more"></a>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> tkinter <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span><span class="params">()</span>:</span></span><br><span class="line"> </span><br><span class="line">  <span class="function"><span class="keyword">def</span> <span class="title">sendMsg</span><span class="params">()</span>:</span><span class="comment">#发送消息</span></span><br><span class="line">    strMsg = <span class="string">'我:'</span> + time.strftime(<span class="string">"%Y-%m-%d %H:%M:%S"</span>,</span><br><span class="line">                                    time.localtime()) + <span class="string">'\n '</span></span><br><span class="line">    txtMsgList.insert(END, strMsg, <span class="string">'greencolor'</span>)</span><br><span class="line">    txtMsgList.insert(END, txtMsg.get(<span class="string">'0.0'</span>, END))</span><br><span class="line">    txtMsg.delete(<span class="string">'0.0'</span>, END)</span><br><span class="line">     </span><br><span class="line">  <span class="function"><span class="keyword">def</span> <span class="title">cancelMsg</span><span class="params">()</span>:</span><span class="comment">#取消消息</span></span><br><span class="line">    txtMsg.delete(<span class="string">'0.0'</span>, END)</span><br><span class="line"> </span><br><span class="line">  <span class="function"><span class="keyword">def</span> <span class="title">sendMsgEvent</span><span class="params">(event)</span>:</span> <span class="comment">#发送消息事件</span></span><br><span class="line">    <span class="keyword">if</span> event.keysym == <span class="string">"Up"</span>:</span><br><span class="line">      sendMsg()</span><br><span class="line"> </span><br><span class="line">  <span class="comment">#创建窗口 </span></span><br><span class="line">  t = Tk()</span><br><span class="line">  t.title(<span class="string">'与python聊天中'</span>)</span><br><span class="line">       </span><br><span class="line">  <span class="comment">#创建frame容器</span></span><br><span class="line">  frmLT = Frame(width=<span class="number">500</span>, height=<span class="number">320</span>, bg=<span class="string">'white'</span>)</span><br><span class="line">  frmLC = Frame(width=<span class="number">500</span>, height=<span class="number">150</span>, bg=<span class="string">'white'</span>)</span><br><span class="line">  frmLB = Frame(width=<span class="number">500</span>, height=<span class="number">30</span>)</span><br><span class="line">  frmRT = Frame(width=<span class="number">200</span>, height=<span class="number">500</span>)</span><br><span class="line">   </span><br><span class="line">  <span class="comment">#创建控件</span></span><br><span class="line">  txtMsgList = Text(frmLT)</span><br><span class="line">  txtMsgList.tag_config(<span class="string">'greencolor'</span>, foreground=<span class="string">'#008C00'</span>)<span class="comment">#创建tag</span></span><br><span class="line">  txtMsg = Text(frmLC);</span><br><span class="line">  txtMsg.bind(<span class="string">"&lt;KeyPress-Up&gt;"</span>, sendMsgEvent)</span><br><span class="line">  btnSend = Button(frmLB, text=<span class="string">'发 送'</span>, width = <span class="number">8</span>, command=sendMsg)</span><br><span class="line">  btnCancel = Button(frmLB, text=<span class="string">'取消'</span>, width = <span class="number">8</span>, command=cancelMsg)</span><br><span class="line">  <span class="string">'''imgInfo = PhotoImage(file = "python.gif")</span></span><br><span class="line"><span class="string">  lblImage = Label(frmRT, image = imgInfo)</span></span><br><span class="line"><span class="string">  lblImage.image = imgInfo'''</span></span><br><span class="line"> </span><br><span class="line">  <span class="comment">#窗口布局</span></span><br><span class="line">  frmLT.grid(row=<span class="number">0</span>, column=<span class="number">0</span>, columnspan=<span class="number">2</span>, padx=<span class="number">1</span>, pady=<span class="number">3</span>)</span><br><span class="line">  frmLC.grid(row=<span class="number">1</span>, column=<span class="number">0</span>, columnspan=<span class="number">2</span>, padx=<span class="number">1</span>, pady=<span class="number">3</span>)</span><br><span class="line">  frmLB.grid(row=<span class="number">2</span>, column=<span class="number">0</span>, columnspan=<span class="number">2</span>)</span><br><span class="line">  frmRT.grid(row=<span class="number">0</span>, column=<span class="number">2</span>, rowspan=<span class="number">3</span>, padx=<span class="number">2</span>, pady=<span class="number">3</span>)</span><br><span class="line">  <span class="comment">#固定大小</span></span><br><span class="line">  frmLT.grid_propagate(<span class="number">0</span>)</span><br><span class="line">  frmLC.grid_propagate(<span class="number">0</span>)</span><br><span class="line">  frmLB.grid_propagate(<span class="number">0</span>)</span><br><span class="line">  frmRT.grid_propagate(<span class="number">0</span>)</span><br><span class="line">   </span><br><span class="line">  btnSend.grid(row=<span class="number">2</span>, column=<span class="number">0</span>)</span><br><span class="line">  btnCancel.grid(row=<span class="number">2</span>, column=<span class="number">1</span>)</span><br><span class="line">  <span class="comment">#lblImage.grid()</span></span><br><span class="line">  txtMsgList.grid()</span><br><span class="line">  txtMsg.grid()</span><br><span class="line"> </span><br><span class="line">  <span class="comment">#主事件循环</span></span><br><span class="line">  t.mainloop()</span><br><span class="line"> </span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    main()</span><br></pre></td></tr></table></figure>
<img src="/images/与python聊天.png" width="100%">

<p>时钟设计：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> turtle <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> datetime <span class="keyword">import</span> *</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">Skip</span><span class="params">(step)</span>:</span></span><br><span class="line">    penup()</span><br><span class="line">    forward(step)</span><br><span class="line">    pendown()</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">mkHand</span><span class="params">(name, length)</span>:</span></span><br><span class="line">    <span class="comment">#注册Turtle形状，建立表针Turtle</span></span><br><span class="line">    reset()</span><br><span class="line">    Skip(-length*<span class="number">0.1</span>)</span><br><span class="line">    begin_poly()</span><br><span class="line">    forward(length*<span class="number">1.1</span>)</span><br><span class="line">    end_poly()</span><br><span class="line">    handForm = get_poly()</span><br><span class="line">    register_shape(name, handForm)</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">Init</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="keyword">global</span> secHand, minHand, hurHand, printer</span><br><span class="line">    mode(<span class="string">"logo"</span>)<span class="comment"># 重置Turtle指向北</span></span><br><span class="line">    <span class="comment">#建立三个表针Turtle并初始化</span></span><br><span class="line">    mkHand(<span class="string">"secHand"</span>, <span class="number">125</span>)</span><br><span class="line">    mkHand(<span class="string">"minHand"</span>,  <span class="number">130</span>)</span><br><span class="line">    mkHand(<span class="string">"hurHand"</span>, <span class="number">90</span>)</span><br><span class="line">    secHand = Turtle()</span><br><span class="line">    secHand.shape(<span class="string">"secHand"</span>)</span><br><span class="line">    minHand = Turtle()</span><br><span class="line">    minHand.shape(<span class="string">"minHand"</span>)</span><br><span class="line">    hurHand = Turtle()</span><br><span class="line">    hurHand.shape(<span class="string">"hurHand"</span>)</span><br><span class="line">    <span class="keyword">for</span> hand <span class="keyword">in</span> secHand, minHand, hurHand:</span><br><span class="line">        hand.shapesize(<span class="number">1</span>, <span class="number">1</span>, <span class="number">3</span>)</span><br><span class="line">        hand.speed(<span class="number">0</span>)</span><br><span class="line">    <span class="comment">#建立输出文字Turtle</span></span><br><span class="line">    printer = Turtle()</span><br><span class="line">    printer.hideturtle()</span><br><span class="line">    printer.penup()</span><br><span class="line">     </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">SetupClock</span><span class="params">(radius)</span>:</span></span><br><span class="line">    <span class="comment">#建立表的外框</span></span><br><span class="line">    reset()</span><br><span class="line">    pensize(<span class="number">7</span>)</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">60</span>):</span><br><span class="line">        Skip(radius)</span><br><span class="line">        <span class="keyword">if</span> i % <span class="number">5</span> == <span class="number">0</span>:</span><br><span class="line">            forward(<span class="number">20</span>)</span><br><span class="line">            Skip(-radius<span class="number">-20</span>)</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            dot(<span class="number">5</span>)</span><br><span class="line">            Skip(-radius)</span><br><span class="line">        right(<span class="number">6</span>)</span><br><span class="line">         </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">Week</span><span class="params">(t)</span>:</span>    </span><br><span class="line">    week = [<span class="string">"星期一"</span>, <span class="string">"星期二"</span>, <span class="string">"星期三"</span>,</span><br><span class="line">            <span class="string">"星期四"</span>, <span class="string">"星期五"</span>, <span class="string">"星期六"</span>, <span class="string">"星期日"</span>]</span><br><span class="line">    <span class="keyword">return</span> week[t.weekday()]</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">Date</span><span class="params">(t)</span>:</span></span><br><span class="line">    y = t.year</span><br><span class="line">    m = t.month</span><br><span class="line">    d = t.day</span><br><span class="line">    <span class="keyword">return</span> <span class="string">"%s %d %d"</span> % (y, m, d)</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">Tick</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="comment">#绘制表针的动态显示</span></span><br><span class="line">    t = datetime.today()</span><br><span class="line">    second = t.second + t.microsecond*<span class="number">0.000001</span></span><br><span class="line">    minute = t.minute + second/<span class="number">60.0</span></span><br><span class="line">    hour = t.hour + minute/<span class="number">60.0</span></span><br><span class="line">    secHand.setheading(<span class="number">6</span>*second)</span><br><span class="line">    minHand.setheading(<span class="number">6</span>*minute)</span><br><span class="line">    hurHand.setheading(<span class="number">30</span>*hour)</span><br><span class="line">     </span><br><span class="line">    tracer(<span class="literal">False</span>)  </span><br><span class="line">    printer.forward(<span class="number">65</span>)</span><br><span class="line">    printer.write(Week(t), align=<span class="string">"center"</span>,</span><br><span class="line">                  font=(<span class="string">"Courier"</span>, <span class="number">14</span>, <span class="string">"bold"</span>))</span><br><span class="line">    printer.back(<span class="number">130</span>)</span><br><span class="line">    printer.write(Date(t), align=<span class="string">"center"</span>,</span><br><span class="line">                  font=(<span class="string">"Courier"</span>, <span class="number">14</span>, <span class="string">"bold"</span>))</span><br><span class="line">    printer.home()</span><br><span class="line">    tracer(<span class="literal">True</span>)</span><br><span class="line"> </span><br><span class="line">    ontimer(Tick, <span class="number">100</span>)<span class="comment">#100ms后继续调用tick</span></span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span><span class="params">()</span>:</span></span><br><span class="line">    tracer(<span class="literal">False</span>)</span><br><span class="line">    Init()</span><br><span class="line">    SetupClock(<span class="number">160</span>)</span><br><span class="line">    tracer(<span class="literal">True</span>)</span><br><span class="line">    Tick()</span><br><span class="line">    mainloop()</span><br><span class="line"> </span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">"__main__"</span>:       </span><br><span class="line">    main()</span><br></pre></td></tr></table></figure>
<p>结果如下：<br><img src="/images/时钟.png" width="100%"></p>
<p>雪景图：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> turtle <span class="keyword">import</span> *</span><br><span class="line"><span class="keyword">from</span> random <span class="keyword">import</span> *   </span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">ground</span><span class="params">()</span>:</span></span><br><span class="line">    hideturtle()</span><br><span class="line">    speed(<span class="number">100</span>)</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">400</span>):</span><br><span class="line">        pensize(randint(<span class="number">5</span>,<span class="number">10</span>))</span><br><span class="line">        x = randint(<span class="number">-400</span>,<span class="number">350</span>)</span><br><span class="line">        y = randint(<span class="number">-280</span>,<span class="number">-1</span>)</span><br><span class="line">        r = -y/<span class="number">280</span></span><br><span class="line">        g = -y/<span class="number">280</span></span><br><span class="line">        b = -y/<span class="number">280</span></span><br><span class="line">        pencolor((r, g, b))</span><br><span class="line">        penup()</span><br><span class="line">        goto(x,y)</span><br><span class="line">        pendown()</span><br><span class="line">        forward(randint(<span class="number">40</span>,<span class="number">100</span>))</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">snow</span><span class="params">()</span>:</span>    </span><br><span class="line">    hideturtle()</span><br><span class="line">    pensize(<span class="number">2</span>)</span><br><span class="line">    speed(<span class="number">100</span>)</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(<span class="number">100</span>):</span><br><span class="line">        r = random()</span><br><span class="line">        g = random()</span><br><span class="line">        b = random()</span><br><span class="line">        pencolor(r, g, b)</span><br><span class="line">        penup()</span><br><span class="line">        setx(randint(<span class="number">-350</span>,<span class="number">350</span>))</span><br><span class="line">        sety(randint(<span class="number">1</span>,<span class="number">270</span>))</span><br><span class="line">        pendown()</span><br><span class="line">        dens = randint(<span class="number">8</span>,<span class="number">12</span>)</span><br><span class="line">        snowsize = randint(<span class="number">10</span>,<span class="number">14</span>)</span><br><span class="line">        <span class="keyword">for</span> j <span class="keyword">in</span> range(dens):</span><br><span class="line">            forward(snowsize)</span><br><span class="line">            backward(snowsize)</span><br><span class="line">            right(<span class="number">360</span>/dens)</span><br><span class="line">         </span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span><span class="params">()</span>:</span></span><br><span class="line">    setup(<span class="number">800</span>, <span class="number">600</span>, <span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">    tracer(<span class="literal">False</span>)</span><br><span class="line">    bgcolor(<span class="string">"black"</span>)    </span><br><span class="line">    snow()</span><br><span class="line">    ground()</span><br><span class="line">    tracer(<span class="literal">True</span>)</span><br><span class="line">    mainloop()</span><br><span class="line">     </span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">"__main__"</span>:</span><br><span class="line">    main()</span><br></pre></td></tr></table></figure>
<p>结果如下：<br><img src="/images/snowfall.png" width="100%"></p>
<p>彩虹：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> turtle <span class="keyword">import</span> *</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">HSB2RGB</span><span class="params">(hues)</span>:</span></span><br><span class="line">    hues = hues * <span class="number">3.59</span> <span class="comment">#100转成359范围</span></span><br><span class="line">    rgb=[<span class="number">0.0</span>,<span class="number">0.0</span>,<span class="number">0.0</span>]</span><br><span class="line">    i = int(hues/<span class="number">60</span>)%<span class="number">6</span></span><br><span class="line">    f = hues/<span class="number">60</span> -i</span><br><span class="line">    <span class="keyword">if</span> i == <span class="number">0</span>:</span><br><span class="line">        rgb[<span class="number">0</span>] = <span class="number">1</span>; rgb[<span class="number">1</span>] = f; rgb[<span class="number">2</span>] = <span class="number">0</span></span><br><span class="line">    <span class="keyword">elif</span> i == <span class="number">1</span>:</span><br><span class="line">        rgb[<span class="number">0</span>] = <span class="number">1</span>-f; rgb[<span class="number">1</span>] = <span class="number">1</span>; rgb[<span class="number">2</span>] = <span class="number">0</span></span><br><span class="line">    <span class="keyword">elif</span> i == <span class="number">2</span>:</span><br><span class="line">        rgb[<span class="number">0</span>] = <span class="number">0</span>; rgb[<span class="number">1</span>] = <span class="number">1</span>; rgb[<span class="number">2</span>] = f</span><br><span class="line">    <span class="keyword">elif</span> i == <span class="number">3</span>:</span><br><span class="line">        rgb[<span class="number">0</span>] = <span class="number">0</span>; rgb[<span class="number">1</span>] = <span class="number">1</span>-f; rgb[<span class="number">2</span>] = <span class="number">1</span></span><br><span class="line">    <span class="keyword">elif</span> i == <span class="number">4</span>:</span><br><span class="line">        rgb[<span class="number">0</span>] = f; rgb[<span class="number">1</span>] = <span class="number">0</span>; rgb[<span class="number">2</span>] = <span class="number">1</span></span><br><span class="line">    <span class="keyword">elif</span> i == <span class="number">5</span>:</span><br><span class="line">        rgb[<span class="number">0</span>] = <span class="number">1</span>; rgb[<span class="number">1</span>] = <span class="number">0</span>; rgb[<span class="number">2</span>] = <span class="number">1</span>-f</span><br><span class="line">    <span class="keyword">return</span> rgb</span><br><span class="line">     </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">rainbow</span><span class="params">()</span>:</span></span><br><span class="line">    hues = <span class="number">0.0</span></span><br><span class="line">    color(<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>)</span><br><span class="line">    <span class="comment">#绘制彩虹</span></span><br><span class="line">    hideturtle()</span><br><span class="line">    speed(<span class="number">100</span>)</span><br><span class="line">    pensize(<span class="number">3</span>)</span><br><span class="line">    penup()</span><br><span class="line">    goto(<span class="number">-400</span>,<span class="number">-300</span>)</span><br><span class="line">    pendown()</span><br><span class="line">    right(<span class="number">110</span>)</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range (<span class="number">100</span>):</span><br><span class="line">        circle(<span class="number">1000</span>)</span><br><span class="line">        right(<span class="number">0.13</span>)</span><br><span class="line">        hues = hues + <span class="number">1</span></span><br><span class="line">        rgb = HSB2RGB(hues)</span><br><span class="line">        color(rgb[<span class="number">0</span>],rgb[<span class="number">1</span>],rgb[<span class="number">2</span>])    </span><br><span class="line">    penup()</span><br><span class="line">     </span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span><span class="params">()</span>:</span></span><br><span class="line">    setup(<span class="number">800</span>, <span class="number">600</span>, <span class="number">0</span>, <span class="number">0</span>)</span><br><span class="line">    bgcolor((<span class="number">0.8</span>, <span class="number">0.8</span>, <span class="number">1.0</span>))</span><br><span class="line">    tracer(<span class="literal">False</span>)</span><br><span class="line">    rainbow()</span><br><span class="line">    <span class="comment">#输出文字</span></span><br><span class="line">    tracer(<span class="literal">False</span>)</span><br><span class="line">    goto(<span class="number">100</span>,<span class="number">-100</span>)</span><br><span class="line">    pendown()</span><br><span class="line">    color(<span class="string">"red"</span>)</span><br><span class="line">    write(<span class="string">"Rainbow"</span>,align=<span class="string">"center"</span>,</span><br><span class="line">          font=(<span class="string">"Script MT Bold"</span>, <span class="number">80</span>, <span class="string">"bold"</span>))</span><br><span class="line">    tracer(<span class="literal">True</span>)</span><br><span class="line">     </span><br><span class="line">    mainloop()</span><br><span class="line"> </span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">"__main__"</span>:</span><br><span class="line">    main()</span><br></pre></td></tr></table></figure>
<img src="/images/Rainbow.png" width="100%">
    </div>

    
    
    
      
        <div class="reward-container">
  <div>这么精彩！不赞一个吗！^_^</div>
  <button disable="enable" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/wechatpay.png" alt="chasemyking 微信支付">
        <p>微信支付</p>
      </div>
      
      <div style="display: inline-block;">
        <img src="/images/alipay.jpg" alt="chasemyking 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E8%AE%A1%E7%AE%97%E6%9C%BA/" rel="tag"># 计算机</a>
              <a href="/tags/%E8%AF%AD%E8%A8%80/" rel="tag"># 语言</a>
              <a href="/tags/python/" rel="tag"># python</a>
              <a href="/tags/%E4%BA%A4%E4%BA%92%E5%BC%8F%E5%9B%BE%E5%BD%A2%E7%BC%96%E7%A8%8B/" rel="tag"># 交互式图形编程</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
                <a href="/2019/12/18/%E5%9B%BE%E5%BD%A2%E7%BC%96%E7%A8%8B/" rel="next" title="图形编程">
                  <i class="fa fa-chevron-left"></i> 图形编程
                </a>
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
            </div>
          </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <img class="site-author-image" itemprop="image" alt="chasemyking"
    src="/images/chasemyking.jpg">
  <p class="site-author-name" itemprop="name">chasemyking</p>
  <div class="site-description" itemprop="description">我永远喜欢艾斯德斯！</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">16</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/chasemyking/chasemyking.github.io" title="GitHub &amp;rarr; https:&#x2F;&#x2F;github.com&#x2F;chasemyking&#x2F;chasemyking.github.io" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="/mailto:cangtiandadi2016@outlook.com" title="E-Mail &amp;rarr; mailto:cangtiandadi2016@outlook.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">chasemyking</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    <span title="站点总字数">59k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">54 分钟</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.0.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> v7.5.0
  </div>

        






  <script>
  function leancloudSelector(url) {
    return document.getElementById(url).querySelector('.leancloud-visitors-count');
  }
  if (CONFIG.page.isPost) {
    function addCount(Counter) {
      var visitors = document.querySelector('.leancloud_visitors');
      var url = visitors.getAttribute('id').trim();
      var title = visitors.getAttribute('data-flag-title').trim();

      Counter('get', `/classes/Counter?where=${JSON.stringify({ url })}`)
        .then(response => response.json())
        .then(({ results }) => {
          if (results.length > 0) {
            var counter = results[0];
            Counter('put', '/classes/Counter/' + counter.objectId, { time: { '__op': 'Increment', 'amount': 1 } })
              .then(response => response.json())
              .then(() => {
                leancloudSelector(url).innerText = counter.time + 1;
              })
              .catch(error => {
                console.log('Failed to save visitor count', error);
              })
          } else {
              leancloudSelector(url).innerText = 'Counter not initialized! More info at console err msg.';
              console.error('ATTENTION! LeanCloud counter has security bug, see how to solve it here: https://github.com/theme-next/hexo-leancloud-counter-security. \n However, you can still use LeanCloud without security, by setting `security` option to `false`.');
            
          }
        })
        .catch(error => {
          console.log('LeanCloud Counter Error', error);
        });
    }
  } else {
    function showTime(Counter) {
      var visitors = document.querySelectorAll('.leancloud_visitors');
      var entries = [...visitors].map(element => {
        return element.getAttribute('id').trim();
      });

      Counter('get', `/classes/Counter?where=${JSON.stringify({ url: { '$in': entries } })}`)
        .then(response => response.json())
        .then(({ results }) => {
          if (results.length === 0) {
            document.querySelectorAll('.leancloud_visitors .leancloud-visitors-count').forEach(element => {
              element.innerText = 0;
            });
            return;
          }
          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.url;
            var time = item.time;
            leancloudSelector(url).innerText = time;
          }
          for (var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = leancloudSelector(url);
            if (element.innerText == '') {
              element.innerText = 0;
            }
          }
        })
        .catch(error => {
          console.log('LeanCloud Counter Error', error);
        });
    }
  }

  fetch('https://app-router.leancloud.cn/2/route?appId=F1yOARDU4POU2Iuir3vgWVrB-gzGzoHsz')
    .then(response => response.json())
    .then(({ api_server }) => {
      var Counter = (method, url, data) => {
        return fetch(`https://${api_server}/1.1${url}`, {
          method: method,
          headers: {
            'X-LC-Id': 'F1yOARDU4POU2Iuir3vgWVrB-gzGzoHsz',
            'X-LC-Key': 'ADyvs9fVUxLnHglgfNMBDNlr',
            'Content-Type': 'application/json',
          },
          body: JSON.stringify(data)
        });
      };
      if (CONFIG.page.isPost) {
        const localhost = /http:\/\/(localhost|127.0.0.1|0.0.0.0)/;
        if (localhost.test(document.URL)) return;
        addCount(Counter);
      } else if (document.querySelectorAll('.post-title-link').length >= 1) {
        showTime(Counter);
      }
    });
  </script>






        
      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script>
<script src="/js/schemes/pisces.js"></script>
<script src="/js/next-boot.js"></script>



  
















  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/assets/miku.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"react":{"opacity":0.7},"log":false});</script></body>
</html>
